import 'package:flutter/material.dart';
import 'package:smart_shop/model/shop_type.dart';
import 'package:smart_shop/page/shop/apply.dart';
import 'package:smart_shop/page/shop/info.dart';
import 'package:smart_shop/utils/colorUtils.dart';

/// 商铺管理
class Shop extends StatefulWidget {
  const Shop({super.key});

  @override
  State<Shop> createState() => _ShopState();
}

class _ShopState extends State<Shop>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  late ScrollController _controller;

  late List<ShopType> types = [];

  @override
  void initState() {
    super.initState();
    _controller = ScrollController();
    types.add(ShopType('打扫·钟点工', 1));
    types.add(ShopType('家电清洗', 2));
    types.add(ShopType('做饭', 3));
    types.add(ShopType('月嫂', 4));
    types.add(ShopType('接送孩子', 5));
    types.add(ShopType('照顾老人/伤病人员', 6));
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: AppBar(
          title: Text('商铺管理',
              style: TextStyle(
                  fontSize: 20,
                  fontFamily: 'PingFangSC-Regular',
                  color: ColorUtils.fromHex('#212121'),
                  fontWeight: FontWeight.normal)),
          centerTitle: false,
          backgroundColor: Colors.white,
          primary: true,
          shadowColor: Colors.transparent,
          bottomOpacity: 0.0),
      body: Padding(
        padding: const EdgeInsets.all(10),
        child: ListView(
          controller: _controller,
          physics: const BouncingScrollPhysics(),
          itemExtent: 94,
          children: [
            GestureDetector(
              child: Container(
                margin: const EdgeInsets.only(bottom: 10),
                decoration: BoxDecoration(
                    borderRadius: const BorderRadius.all(Radius.circular(6)),
                    color: Colors.white,
                    border: Border.all(
                        color: const Color.fromRGBO(54, 54, 90, 0.3))),
                padding: const EdgeInsets.all(6),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Align(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '北海六得很家政服务有限公司',
                        overflow: TextOverflow.ellipsis,
                        textAlign: TextAlign.left,
                        style: TextStyle(
                            color: ColorUtils.fromHex('#1D1D2E'),
                            fontSize: 18,
                            fontWeight: FontWeight.normal,
                            fontFamily: 'Source Han Sans CN'),
                      ),
                    ),
                    Container(
                      margin: const EdgeInsets.symmetric(vertical: 4),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text('服务/商品类型数：6',
                              style: TextStyle(
                                  color: ColorUtils.fromHex('#9E9E9E'),
                                  fontSize: 14,
                                  fontWeight: FontWeight.normal,
                                  fontFamily: 'Source Han Sans CN')),
                          Text('营业中',
                              style: TextStyle(
                                  color: ColorUtils.fromHex('#11BF08'),
                                  fontSize: 14,
                                  fontWeight: FontWeight.normal,
                                  fontFamily: 'Source Han Sans CN'))
                        ],
                      ),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text('订单数：99',
                            style: TextStyle(
                                color: ColorUtils.fromHex('#9E9E9E'),
                                fontSize: 14,
                                fontWeight: FontWeight.normal,
                                fontFamily: 'Source Han Sans CN')),
                        Text('进行中：3',
                            style: TextStyle(
                                color: ColorUtils.fromHex('#6B8EF6'),
                                fontSize: 14,
                                fontWeight: FontWeight.normal,
                                fontFamily: 'Source Han Sans CN'))
                      ],
                    )
                  ],
                ),
              ),
              onTap: () {
                // 动画效果
                Navigator.of(context).push(PageRouteBuilder(
                    pageBuilder: (BuildContext context,
                        Animation<double> animation,
                        Animation<double> secondaryAnimation) {
                      return const ShopInfo();
                    },
                    transitionDuration: const Duration(milliseconds: 500),
                    transitionsBuilder:
                        (context, animation, secondaryAnimation, child) {
                      const begin = Offset(1.0, 0.0);
                      const end = Offset.zero;
                      final tween = Tween(begin: begin, end: end)
                          .chain(CurveTween(curve: Curves.linear));
                      final offsetAnimation = animation.drive(tween);
                      return SlideTransition(
                        position: offsetAnimation,
                        child: child,
                      );
                    }));
              },
            ),
            Container(
              margin: const EdgeInsets.only(top: 10),
              padding: const EdgeInsets.only(top: 10),
              alignment: Alignment.topCenter,
              child: MaterialButton(
                color: ColorUtils.fromHex('#3D7EFE'),
                height: 48,
                minWidth: 216,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(5.0),
                ),
                child: const Text(
                  '申请新商铺/公司',
                  style: TextStyle(
                      color: Colors.white,
                      fontSize: 18,
                      fontWeight: FontWeight.normal,
                      fontFamily: 'PingFangSC-Regular'),
                ),
                onPressed: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (BuildContext context) {
                    return const ShopApply();
                  }));
                },
              ),
            )
          ],
        ),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
